package com.designschool.base.mail;

import java.io.File;
import java.io.IOException;

import com.designschool.base.notice.EmailListener;
import com.designschool.base.util.MobileUtils;

import android.content.Context;
import android.os.Environment;
import android.util.Log;
/***
 * 
 * @项目名:chake  
 * 
 * @类名:EmailRunnable.java  
 * 
 * @创建人:chakeshe 
 *
 * @类描述:发送邮件
 * 
 * @date:2015-7-26
 * 
 * @Version:1.0 
 *
 *****************************************
 */
public class EmailRunnable implements Runnable,EmailListener {
	
	private String subject;

	private MultiMailsender sender;
	

	private Context context;
	private Throwable e;
	public EmailRunnable(Context mContext) {
		this.context=mContext;
	}

	@Override
	public void run() {
	    sender = new MultiMailsender();
		try {
		    StringBuffer sb = new StringBuffer();
		    sb.append("手机类型:"+MobileUtils.getMobel()+"  系统版本:"+MobileUtils.getRelease()+"\n");
	        StackTraceElement[] ste = e.getStackTrace();
	        for (StackTraceElement e : ste) {
	             sb.append(e.toString()+"\n");
	        }
			sender.sendEmail(subject, sb.toString(), context);
		} catch (Exception e) {
			e.printStackTrace();
		}
		android.os.Process.killProcess(android.os.Process.myPid());
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	@Override
	public void sendMail(String subject,Object e) {
		this.e=(Throwable) e;
		setSubject(subject);
		new Thread(this).start();
	}

}
